<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="s" uri="/struts-tags" %>
<%@taglib prefix="display" uri="http://displaytag.sf.net" %>
<%
	String contextPath = request.getContextPath();
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title></title>
<link href="style/store.css" rel="stylesheet" type="text/css">
<link href="style/displaytagex.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
function onLoadInit(){
	document.getElementById("blah").focus();
}
function submitProduct(e,barcode){
	if(e.keyCode == 13 || e == "submit"){
		document.formName.barcode.value=barcode.value;
		document.formName.action="addToReturnCartAction";
		document.formName.submit();
	}
}

function setSearchProduct(){
	window.open('setSearchProductAction.action', 'Search', config='toolbar=no, scrollbars=yes, location=no, directories=no, status=no');
}

function addProduct(){
	barcode = document.getElementById("blah");
	submitProduct("submit",barcode);
}

function getQnt(qnt,e,barcode,task){
	if(e.keyCode == 13){
	document.formName.quantity.value=qnt.value;
	document.formName.barcode.value=barcode;
	document.formName.action="changeReturnQuantityAction";
	document.formName.submit();		
	}
}

function resetCart(){
	if(confirm("Are you sure?")){
		document.formName.action="resetReturnAction";
		document.formName.submit();
	}else{
		return false;
	}
}

function previousScreen(){
	if(confirm("Go back to previous screen?")){
		document.formName.action="goToReturnProductsAction";
		document.formName.submit();
	}else{
		return false;
	}
}

function doSaveReturnLog(){
	var reason;
	reason = prompt('Input Reason for return:','');
	if(reason != ''){
		document.formName.remarks.value=reason;
		document.formName.action="doSaveReturnLogAction";
		document.formName.submit();
	}else{
		alert("Please input reason");
		doSaveReturnLog();
	}
	
	
}

</script>
</head>
<body onload="onLoadInit();">
<form name="formName" method="post" >
	
	<s:hidden name="dispMode" />
	<input name="prodId" type="hidden" />
	<input name="barcode" type="hidden" />
	<input name="quantity" type="hidden" />
	<input name="remarks" type="hidden" />
	
	<table align="center" width="90%">
		<tr>
			<td>
				<span class="error" >
					<s:actionerror/>
					<s:actionmessage/>
				</span>
			</td>
		</tr>
	</table>
	<s:if test="dispMode == 1 ">
	<div class="optionbox" >
	<s:submit cssClass="button" value="Return Products" action="goToAddReturnProductsAction" ></s:submit>
	</div>
	<table align="center" width="100%">
		<tr>
			<td colspan="3" class="verdana" height="30" align="center" bgcolor="#336699">
				<font color="#ffffff">Returned Products</font>
			</td>
		</tr>
	</table>
	<table align="center" width="100%">
	<tr bgcolor="#e8ecf0" style="font-size: 11px; font-family: Arial, Helvetica, sans-serif" >
	<td>
	<s:set name="returnProductsList" value="returnProductsList" scope="request"></s:set>
	<display:table name="soldProductsList" uid="row" pagesize="20" class="dataTable"
	requestURI="goToReturnProductsAction.action">
		<display:column title="#"> 
  		   ${row_rowNum}
 		 </display:column>
		<display:column property="rp_id" title="Seq No."></display:column>
		<display:column property="returndate" title="Return Date" sortable="true"></display:column>
		<display:column property="returntime" title="Return Time"></display:column>
		<display:column property="totalvalue" title="Total Value"></display:column>
		<display:column>
			<s:url id="view" action="goToViewReturnProductAction">
				<s:param name="rp_id" value="#attr.row.rp_id"></s:param>
			</s:url>
			<s:a href="%{view}">Details</s:a>
		</display:column>
		<display:setProperty name="paging.banner.placement" value="top" />
	</display:table>
	</td></tr>
	</table>
	</center>
	</s:if>
	<s:elseif test="dispMode == 2">
	<table align="center" width="40%">
		<tr>
			<td colspan="2" class="verdana" height="30" align="center" bgcolor="#336699">
				<font color="#ffffff">Return a Product</font>
			</td>
		</tr>
		<tr bgcolor="#e8ecf0" style="font-size: 11px; font-family: Arial, Helvetica, sans-serif" >
			<td>Barcode: <input type="text" name="blah" id="blah" size="40%" onkeypress="return checkKeyPressedNumbersOnly(event);" onkeyup="submitProduct(event,this);" />
				<input type="button" class="button" onclick="setSearchProduct();" value="..." size="4" />
			</td>
		</tr>
	</table>
	<br/>
	<table border="1" align="center" width="60%">
		<tr>
			<td align="right" colspan="4">
				<input type="button" accesskey="x" onclick="previousScreen();" class="button" value="Previous Screen" >
				<input type="button" accesskey="x" onclick="resetCart();" class="button" value="Reset List" >
				<input type="button" accesskey="s" onclick="doSaveReturnLog();" class="button" value="Record Return of Products" > 
			</td>
		</tr>
		<tr>
			<td colspan="4" class="verdana" height="30" align="center" bgcolor="#336699"><font color="#ffffff">Products to be Returned</td>
		</tr>
		<tr bgcolor="#e8ecf0" style="font-size: 11px; font-family: Arial, Helvetica, sans-serif" >
			<td width="45%">Product Name</td>
			<td width="20%">Unit Price</td>
			<td width="20%">Unit(s)</td>
			<td width="15%">Sub Total</td>
		</tr>
		<s:if test="#session.productDTOList != null">
		<s:iterator value="#session.productDTOList">
			<tr bgcolor="#e8ecf0" style="font-size: 11px; font-family: Arial, Helvetica, sans-serif" >	
				<td><s:property value="value.name"/></td>
				<td><s:property value="value.price"/></td>
				<td>
					<input name="blah1" onclick="this.select();" onkeyup="getQnt(this,event,<s:property value='value.barcode'/>,'changeQuantityAction');" type="text" size="3" value="<s:property value='value.quantity'/>" />
				</td>				
				<td><s:property value="value.totalPriceString"/></td>
			</tr>
		</s:iterator>	
			<tr bgcolor="#e8ecf0" style="font-size: 11px; font-family: Arial, Helvetica, sans-serif" >
				<td align="right" colspan="4">Grand Total: <s:property value="grandTotal"/>  </td>
			</tr>
		</s:if>	
		<s:else>
			<tr bgcolor="#e8ecf0" style="font-size: 11px; font-family: Arial, Helvetica, sans-serif" >
				<td colspan="4">No Product to display</td>
			</tr>
		</s:else>	
	</table>
	</s:elseif>
	<s:elseif test="dispMode == 3">
	<table border="1" align="center" width="50%">
			<tr>
				<td colspan="2" class="verdana" height="30" align="center" bgcolor="#336699"><font color="#ffffff">Return Product Details</font></td>
			</tr>
			<tr bgcolor="#e8ecf0" style="font-size: 11px; font-family: Arial, Helvetica, sans-serif" >
				<td><label>Return ID: </label></td>
				<td><s:property value="returnproduct.rp_id" /> </td>
			</tr>
			<tr bgcolor="#e8ecf0" style="font-size: 11px; font-family: Arial, Helvetica, sans-serif" >
				<td><label>Return Date: </label></td>
				<td><s:property value="returnproduct.returndate" /> </td>
			</tr>
			<tr bgcolor="#e8ecf0" style="font-size: 11px; font-family: Arial, Helvetica, sans-serif" >
				<td><label>Return Time: </label></td>
				<td><s:property value="returnproduct.returntime" /> </td>
			</tr>
			<tr bgcolor="#e8ecf0" style="font-size: 11px; font-family: Arial, Helvetica, sans-serif" >
				<td><label>Reason for return: </label></td>
				<td><s:property value="returnproduct.remarks" /> </td>
			</tr>
			<tr>
				<td colspan="2" class="verdana" height="30" align="center" bgcolor="#336699"><font color="#ffffff">Product Returned</font></td>
			</tr>
			<tr>
				<td colspan="2" align="center" width="100%">
					<display:table name="productList" uid="row" pagesize="10" class="dataTable"
						requestURI="goToViewReturnProductAction.action">
						<display:column property="name" title="Product Name"></display:column>
						<display:column property="quantity" title="Quantity"></display:column>
						<display:column property="subTotal" title="Sub Total"></display:column>
					</display:table>
				</td>
			</tr>
			<tr bgcolor="#e8ecf0" style="font-size: 11px; font-family: Arial, Helvetica, sans-serif" >
				<td width="70%" align="right" style="padding-right: 10px" ><label>Grand Total:</label></td>
				<td><s:property value="returnproduct.totalvalue" /> </td>
			</tr>
			<tr style="font-size: 11px; font-family: Arial, Helvetica, sans-serif" >
				<td colspan="2" align="center"><s:submit action="goToReturnProductsAction" value="Back" cssClass="button" /></td>
			</tr>
		</table>
	</s:elseif>
</form>
</body>
</html>